﻿using Abp.Dependency;
using Abp.UI;
using App.Authorization.Users;
using System;

namespace App.Authorization
{
    public class LoginResultTypeHelper : AppServiceBase, ITransientDependency
    {
        public string CreateExceptionForFailedLoginAttempt(LoginResultType result, string usernameOrEmailAddress, string tenancyName)
        {
            switch (result)
            {
                case LoginResultType.Success:
                    return "Don't call this method with a success result!";
                case LoginResultType.InvalidUserNameOrEmailAddress:
                case LoginResultType.InvalidPassword:
                    return "用户名或密码错误";
                case LoginResultType.InvalidTenancyName:
                    return "租户不存在";
                case LoginResultType.TenantIsNotActive:
                    return "租户已禁用";
                case LoginResultType.UserIsNotActive:
                    return "帐户已禁用";
                case LoginResultType.UserEmailIsNotConfirmed:
                    return "邮件帐户未激活";
                default: //Can not fall to default actually. But other result types can be added in the future and we may forget to handle it
                    Logger.Warn("Unhandled login fail reason: " + result);
                    return "未知错误，登录失败";
            }
        }
    }
}
